// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class SPECIMEN_OSM_R26 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("15 SPM",15)]
  	    [HL7Field(HL7Version.v27, 15, HL7Repeat.False, HL7Required.True,"SPM")]
	    public SPM SPM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("16 PRT",16)]
  	    [HL7Field(HL7Version.v27, 16, HL7Repeat.True, HL7Required.False,"PRT")]
	    public PRT[] PRT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("17 SPECIMEN_OBSERVATION",17)]
  	    [HL7Field(HL7Version.v27, 17, HL7Repeat.True, HL7Required.False,"SPECIMEN_OBSERVATION_OSM_R26")]
	    public SPECIMEN_OBSERVATION_OSM_R26[] SPECIMEN_OBSERVATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("21 CONTAINER",21)]
  	    [HL7Field(HL7Version.v27, 21, HL7Repeat.True, HL7Required.False,"CONTAINER_OSM_R26")]
	    public CONTAINER_OSM_R26[] CONTAINER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("28 SUBJECT_PERSON_ANIMAL_IDENTIFICATION",28)]
  	    [HL7Field(HL7Version.v27, 28, HL7Repeat.False, HL7Required.False,"SUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26")]
	    public SUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26 SUBJECT_PERSON_ANIMAL_IDENTIFICATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("37 SUBJECT_POPULATION_LOCATION_IDENTIFICATION",37)]
  	    [HL7Field(HL7Version.v27, 37, HL7Repeat.False, HL7Required.False,"SUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26")]
	    public SUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26 SUBJECT_POPULATION_LOCATION_IDENTIFICATION {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			SPM = PopSegmentParseAndCheckRequired<SPM>(availableData, options, "SPM");
			PRT = PopSegmentParseAndCheckRequiredArray<PRT>(availableData, options, "PRT");
			SPECIMEN_OBSERVATION = ProcessGroupArray<SPECIMEN_OBSERVATION_OSM_R26>(availableData, options, "SPECIMEN_OBSERVATION");
			CONTAINER = ProcessGroupArray<CONTAINER_OSM_R26>(availableData, options, "CONTAINER");
			SUBJECT_PERSON_ANIMAL_IDENTIFICATION = ProcessGroup<SUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26>(availableData, options, "SUBJECT_PERSON_ANIMAL_IDENTIFICATION");
			SUBJECT_POPULATION_LOCATION_IDENTIFICATION = ProcessGroup<SUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26>(availableData, options, "SUBJECT_POPULATION_LOCATION_IDENTIFICATION");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isSPM = availableData.StartsWith("SPM", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("SPM", options.Version) || isSPM) {
				return isSPM;
			}
			bool isPRT = availableData.StartsWith("PRT", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PRT", options.Version) || isPRT) {
				return isPRT;
			}
			SPECIMEN_OBSERVATION_OSM_R26 testSPECIMEN_OBSERVATION_OSM_R26 = new SPECIMEN_OBSERVATION_OSM_R26();
			bool grpCCSPECIMEN_OBSERVATION_OSM_R26 = (testSPECIMEN_OBSERVATION_OSM_R26.CanConsume(availableData, options));
			if (IsRequired("SPECIMEN_OBSERVATION", options.Version) || grpCCSPECIMEN_OBSERVATION_OSM_R26) {
				return grpCCSPECIMEN_OBSERVATION_OSM_R26;
			}
			CONTAINER_OSM_R26 testCONTAINER_OSM_R26 = new CONTAINER_OSM_R26();
			bool grpCCCONTAINER_OSM_R26 = (testCONTAINER_OSM_R26.CanConsume(availableData, options));
			if (IsRequired("CONTAINER", options.Version) || grpCCCONTAINER_OSM_R26) {
				return grpCCCONTAINER_OSM_R26;
			}
			SUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26 testSUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26 = new SUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26();
			bool grpCCSUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26 = (testSUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26.CanConsume(availableData, options));
			if (IsRequired("SUBJECT_PERSON_ANIMAL_IDENTIFICATION", options.Version) || grpCCSUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26) {
				return grpCCSUBJECT_PERSON_ANIMAL_IDENTIFICATION_OSM_R26;
			}
			SUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26 testSUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26 = new SUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26();
			bool grpCCSUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26 = (testSUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26.CanConsume(availableData, options));
			if (IsRequired("SUBJECT_POPULATION_LOCATION_IDENTIFICATION", options.Version) || grpCCSUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26) {
				return grpCCSUBJECT_POPULATION_LOCATION_IDENTIFICATION_OSM_R26;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "SPECIMEN";
			}
        }

        static SPECIMEN_OSM_R26() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(SPECIMEN_OSM_R26));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (SPM != null) {
			string segmentValue = SPM.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PRT != null && PRT.Length > 0) {
			for (int i = 0; i < PRT.Length; i++) {
				string segmentValue = PRT[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (SPECIMEN_OBSERVATION != null && SPECIMEN_OBSERVATION.Length > 0) {
			for (int i = 0; i < SPECIMEN_OBSERVATION.Length; i++) {
				string segmentValue = SPECIMEN_OBSERVATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (CONTAINER != null && CONTAINER.Length > 0) {
			for (int i = 0; i < CONTAINER.Length; i++) {
				string segmentValue = CONTAINER[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (SUBJECT_PERSON_ANIMAL_IDENTIFICATION != null) {
			string segmentValue = SUBJECT_PERSON_ANIMAL_IDENTIFICATION.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (SUBJECT_POPULATION_LOCATION_IDENTIFICATION != null) {
			string segmentValue = SUBJECT_POPULATION_LOCATION_IDENTIFICATION.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

